package service;

import java.util.ArrayList;
import java.util.List;

import dao.ProductDao;
import entity.Product;
import utils.PageUtils;

public class ProductService {
	public ProductDao prodao=new ProductDao();
	/**
	 * 
	 * @param categoryId
	 * @param categoryLeve1
	 * @param currPage 当前页面
	 * @param pageSize  页面大小
	 * @return
	 */
	public List<Product> proList(int categoryId,int categoryLeve1,int currPage,int pageSize){
		int startIndex=(currPage-1)*pageSize;
		return prodao.proList(categoryId,categoryLeve1,startIndex,pageSize);	
	}
	public int procount(int categoryId,int categoryLeve1){
		return prodao.procount(categoryId, categoryLeve1);
	}
	public Product findById(int id) {
		return prodao.findById(id);
	}

	public int subStock(int productId,int quantity){
		return prodao.subStock(productId, quantity);
	}

	public List<Product> findList(int currPageNo, int pageSize){
		int startIndex = (currPageNo-1)*pageSize;
		return prodao.findList(startIndex, pageSize);
	}

	public int findCount(){
		return prodao.findCount();
	}
	
	public PageUtils<Product> findProductsByCategoryId(int categoryId,int categoryLevel,int beginIndex,int pageSize){
		return prodao.findProductsByCategoryId(categoryId, categoryLevel, beginIndex, pageSize);
	}

	public Product getProductById(int id){
		return prodao.getProductById(id);
	}
	
	public PageUtils<Product> findAllProducts(int beginIndex,int pageSize){
		return prodao.findAllProducts(beginIndex, pageSize);
		
	}

	public int add(Product product) {
		return prodao.add(product);
	}

	public int update(Product product) {
		return prodao.update(product);
	}
	 public int deteleProduct(int id){
		 return prodao.deteleProduct(id);
	 }
}
